
// 引入es7 的支持库
import React from 'react';
import {
    Route,
    Switch,
} from 'react-router-dom';
import { connect } from 'react-redux'

// 国际化
import { IntlProvider, addLocaleData } from 'react-intl';

import Home from './routers/Home'

import Loadable from 'react-loadable';    //按需加载组件          

import localeZh from './locale/zh_CN';    //导入 i18n 配置文件
import localeEn from './locale/en_US';

import en from 'react-intl/locale-data/en';
import zh from 'react-intl/locale-data/zh';
addLocaleData([...en, ...zh]);


// 实现按需加载
// const Home = Loadable({
//     loader: () => import('./routers/Home'), 				       //按需加载												
//     loading:()=>(<div>加载中...</div>)
// })

// const Test = Loadable({
//     loader: () => import('./routers/Test'), 				       //按需加载												
//     loading:()=>(<div>加载中...</div>)
// })

// 切换语言
const mapStateToProps = (state) => {
    var obj = { locale: state.get('global').locale, messages: {} }
    if (state.get('global').locale === 'en') obj.messages = localeEn
    if (state.get('global').locale === 'zh') obj.messages = localeZh
    return obj
};
const IntlContainer = connect(mapStateToProps)(IntlProvider);
export default class app extends React.Component {
    render() {

        return (
            <IntlContainer>
                <Switch>
                    <Route exact path="/" component={Home} />
                </Switch>
            </IntlContainer>
        )
    }
}